<template>
  <div class="carg-wrapper">
    <!--      标题-->
    <div class="title">待派送 {{ state.currentDay }}</div>
    <div class="carg-wrapper1">
      <!--      车辆-->
      <div style="text-align: center;overflow: auto;" :style="{height: (state.height - 50) + 'px'}" >
        <template v-if="state.unDeliverCargo.length > 0">
          <div class="item" v-for="(item, index) in state.unDeliverCargo" :key="index" @click="getCar(item)">
            <div class="licence">{{item.deliverNames}}</div>
            <div class="count">
              <span :style="{color: item.nums > 0 ? 'white' : 'grey'}">{{item.nums}}</span>
            </div>
          </div>
        </template>
        <template v-else>
          <div style="margin-top: 100px;font-size: 22px;color: #656D78;">
            无待派送数据~~
          </div>
        </template>
      </div>
    </div>
  </div>
</template>
<script setup>
// 待配送列表
import tool from "@/utils/tool";
import {onBeforeMount, ref} from "vue";
import {useRouter} from "vue-router";
const router = useRouter()
const state = ref({
  title: '',
  usr: {},
  unDeliverCargo: [], // 待送货
  width: window.innerWidth,
  height: window.innerHeight,
  cargoModal: false, // 装车明细弹出 框
  currentCar: {}, // 当前选中车辆
  currentDay: ''
})
onBeforeMount(() => {
  state.value.currentDay = tool.getDay()
  let deliver = tool.data.getUser()
  if (deliver) {
    getCarList()
    state.value.usr = deliver
  } else {
    router.push('/deliver')
  }
})
const getCarList = () => {
  state.value.unDeliverCargo = []
  tool.post('justdeliver/unDeliver', {}, true).then(ret => {
    if(ret.stat) {
      state.value.unDeliverCargo = ret.data
    }
  })
}
const getCar = (item) => {
  router.push({name: 'waitToGoDetail', query: {item: JSON.stringify(item)}})
}

</script>
<style scoped lang="scss">
.title {
  text-align: center;
  font-weight: bold;
  font-size: 22px;
  background-color: #01aaee;
  color: white;
  height: 40px;
  line-height: 40px;
}
$item-color: #3399cc;
.carg-wrapper1 {
  background-color: #f8f8f9;
  text-align: center;
  .item {
    height: 100px;
    width: 150px;
    display: inline-block;
    border: 1px solid $item-color;
    margin: 10px;
    border-radius: 4px;
    color: white;
    background-color: $item-color;
    .licence {
      padding: 20px 0;font-size: 16px;font-weight: bold;
    }
    .count {
      font-size: 16px;font-weight: bold;
    }
    &:active {
      border: 1px solid orangered;
      background-color: orangered;
      color: white;
    }
  }
}
</style>
